package edu.drexel.jrexel2d.objects2D;

import java.util.ArrayList;

import edu.drexel.jrexel2d.animation.Sprite;

public class Polygon extends Object2D {
    protected ArrayList<Line2D> edges ;

    public Polygon(Sprite s, int i, ArrayList<Point2D> ps) {
        super(s, i);
        edges = new ArrayList<Line2D>() ;
        if(ps != null && ps.size() > 0) makeLines(ps) ;
    }
   
    private void makeLines(ArrayList<Point2D> ps) {
        for(int i=0; i<ps.size(); i++) {
        	Point2D p1 = new Point2D (ps.get(i), this.getWidth()/2, -this.getHeight()/2) ;
        	Point2D p2 = new Point2D (ps.get((i+1)%ps.size()), this.getWidth()/2, -this.getHeight()/2) ;
            edges.add(new Line2D(p1, p2)) ;
        }
    }
   
    public ArrayList<Line2D> getEdges() {
        updateEdges() ;
        return edges ;
    }
   
    private void updateEdges() {
        Point2D p = this.getLocation();
        for(Line2D l: edges) {
            l.setCenter(p) ;
        }
    }

}
